import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

import java.util.List;

import static java.lang.Thread.sleep;

public class Main {
    public static void main(String[] args) throws InterruptedException {
        //驱动程序管理的⾃动化
        WebDriverManager.chromedriver().setup();
        ChromeOptions options = new ChromeOptions();

        //允许访问所有链接
        options.addArguments("--remote-allow-origins=*");

        //1、打开浏览器
        WebDriver driver = new ChromeDriver(options);

        //2.输⼊百度⽹址:https://www.baidu.com
        driver.get("https://www.baidu.com");

        //3、找到输⼊框并输⼊“迪丽热巴”
        /*WebElement element = driver.findElement(By.cssSelector(".s_ipt"));
        element.sendKeys("软件测试");*/

        driver.findElement(By.xpath("//*[@id=\"kw\"]")).sendKeys("吴彦祖");
        //4、找到“百度⼀下”按钮并点击
        driver.findElement(By.xpath("//*[@id=\"su\"]")).click();
        sleep(3000);
        driver.navigate().back();


        /*//校验
        List<WebElement> elements = driver.findElements(By.cssSelector("a em"));
        for (int i= 0; i < elements.size(); i++) {
            if (!elements.get(i).getText().equals("吴彦祖")) {
                System.out.println("测试不通过");
            }else{
                System.out.println("测试通过");
            }
        }*/
        //5、关闭浏览器
        driver.quit();
    }
}
